package com.face.console.service.impl;

import com.face.console.dao.FieldDtoMapper;
import com.face.console.pojo.dto.FieldDto;
import com.face.console.pojo.vo.FieldVo;
import com.face.console.service.FieldDtoService;
import com.face.console.tools.SnowFlakeUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Description: face场馆业务实现类
 * <p>
 * Created by Andy_Lau on 2020/12/27 23:45
 */
@Service
public class FieldDtoImpl implements FieldDtoService {

    @Autowired
    private FieldDtoMapper fieldDtoMapper;

    @Override
    public void insertField(FieldDto field) {
        field.setId(SnowFlakeUtil.getFlowIdInstance().nextId());
        int num = fieldDtoMapper.insert(field);
        if (num == 1){
            System.out.println("场馆插入成功");
        }
    }

    @Override
    public FieldVo queryFieldById(Long id) {
        FieldDto entity =fieldDtoMapper.selectByPrimaryKey(id);
        if (entity!=null) {
            FieldVo fieldVo = new FieldVo();
            BeanUtils.copyProperties(entity,fieldVo);
            return fieldVo;
        }
       return null;
    }

    @Override
    public List<FieldVo> fieldVos(FieldDto query){
        return fieldDtoMapper.fields(query);
    }

    @Override
    public boolean deleteByPrimaryKey(Long id) {
        return fieldDtoMapper.deleteByPrimaryKey(id) > 0 ? true : false;
    }
}
